#include "HiVisualiser.hpp"
#include <cv.h>

#include <string>

/*
 *  Visualiser.cpp
 *  
 *
 *  Created by Rasmus Kyng on 28/01/2011.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

//FIXNOW: Leaky as it is static

using namespace cv;
using namespace std;

//HiVisualiser::windowMatrixMap = map< string, cv::Mat >();

map< string, Mat > HiVisualiser::windowMatrixMap = map< string, Mat >();

void HiVisualiser::addWindow( string windowName ) {
	HiVisualiser::windowMatrixMap[windowName] = Mat();
	namedWindow( windowName );
}
void HiVisualiser::refreshWindow( string windowName ) {
	if ( windowMatrixMap.find(windowName) == windowMatrixMap.end() ) {
		CV_Error( CV_StsError, "HiVisualiser cannot show window when no matrix is set!");
	}
	imshow( windowName, windowMatrixMap[windowName] );
}
void HiVisualiser::moveWindow( string windowName, int x, int y ) {
	char* cstr = new char [windowName.size()+1];
	strcpy (cstr, windowName.c_str());

	cvMoveWindow( cstr, x, y);
	
	delete[] cstr;
}
cv::Mat HiVisualiser::getMatrix( string windowName ) {
	return windowMatrixMap[windowName];
}
void HiVisualiser::setMatrix( string windowName, cv::Mat matrix ) {
	windowMatrixMap[windowName] = matrix;
}